﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HA.ModFlow.Domain.FileLayer
{
    public class PEvapotranspiration : Package
    {


        public PEvapotranspiration()
        {
            this._fileType = FileType.EVT;

            this.Fname = "solution.evt";

            this.Nunit = 47;

        }

        int _NEVTOP;
        /// <summary>
        /// 蒸散选项 1 ，2 
        /// </summary>
        public int NEVTOP
        {
            get { return _NEVTOP; }
            set { _NEVTOP = value; }
        }



        int _IEVTCB = 107;

        /// <summary>
        /// cellbycell 标志位
        /// </summary>
        public int IEVTCB
        {
            get { return _IEVTCB; }
            set { _IEVTCB = value; }
        }






        List<SPEVT> _stressPeriodEVT = new List<SPEVT>();

        public List<SPEVT> StressPeriodEVT
        {
            get { return _stressPeriodEVT; }

        }






        public override void WriteFile(string path)
        {
            string content = "# HuanAnKeJi EVT File" + "\r\n";
            content += string.Format("{0,10}", this.NEVTOP) +" "+ string.Format("{0,10}", this.IEVTCB) + "\r\n";
            string str = "";
            string str1 = "";
            string str2 = "";
            string str3 = "";
            string str4 = "";
            foreach (SPEVT sp in StressPeriodEVT)
            {
                str += string.Format("{0,10}", sp.INSURF) + " " + string.Format("{0,10}", sp.INEVTR) + " " + string.Format("{0,10}", sp.INEXDP) + " " + string.Format("{0,10}", sp.INIEVT) + "\r\n";
                if (sp.INSURF >= 0)
                {
                    if (IsConstant(sp.SURF))
                    {
                        str += "CONSTANT " + string.Format("{0,10}", sp.SURF[0, 0]) + "\r\n";
                    }
                    else
                    {
                        str += "INTERNAL   1.0 (FREE)  19" + "\r\n";
                        if (GetArrayString(sp.SURF, ref  str1))
                        {
                            str += str1;
                        }
                    }
                }
              

                if (sp.INEVTR >= 0)
                {
                    if (IsConstant(sp.EVTR))
                    {
                        str += "CONSTANT " + string.Format("{0,10}", sp.EVTR[0, 0]) + "\r\n";
                    }
                    else
                    {
                        str += "INTERNAL   1.0 (FREE)  19" + "\r\n";
                        if (GetArrayString(sp.EVTR, ref  str2))
                        {
                            str += str2;
                        }
                    }
                }
               

                if (sp.INEXDP >= 0)
                { 
                    if (IsConstant(sp.EXDP))
                    {
                        str += "CONSTANT " + string.Format("{0,10}", sp.EXDP[0, 0]) + "\r\n";
                    }
                    else
                    {
                        str += "INTERNAL   1.0 (FREE)  19" + "\r\n";
                        if (GetArrayString(sp.EXDP, ref  str3))
                        {
                            str += str3;
                        }
                    }
                }
              

                if (sp.INIEVT >= 0)
                {                  
                    if (IsConstant(sp.IEVT))
                    {
                        str += "CONSTANT " + string.Format("{0,10}", sp.IEVT[0, 0]) + "\r\n";
                    }
                    else
                    {
                        str += "INTERNAL   1.0 (FREE)  9" + "\r\n";
                        if (GetArrayString(sp.IEVT, ref  str4))
                        {
                            str += str4;
                        }
                    }
                }
            }
            content +=str;


            string fname = path + this.Fname;
            HAUtil.FileOperations.WriteFile(fname, content);
        }
    }
}
